package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.LinkBean;
import com.project.service.ILinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/link")
public class LinkController {
    @Autowired
    private ILinkService service;

    @RequestMapping("/findAll")
    public String findAll(@RequestParam(value = "pageNO",defaultValue = "1") int pageNO, HttpServletRequest request){
       PageInfo<LinkBean> info = service.cutPage(pageNO);
        request.setAttribute("list",info);
        return "/html/main.html";
    }
    @RequestMapping("add")
    public String add(LinkBean linkBean){
        service.add(linkBean);
        return "redirect:/link/findAll";
    }
    @RequestMapping("update")
    public String update(int id, Model model){
        LinkBean link=service.findById(id);
        model.addAttribute("link",link);
        return "/html/update.html";
    }
    @RequestMapping("change")
    public String changePhone(int id,String phone){
        service.update(id, phone);
        return "redirect:/link/findAll";
    }
    @RequestMapping("del")
    public String delete(int id){
        service.del(id);
        return "redirect:/link/findAll";
    }
}
